package com.example.admin.yuejian_22.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.admin.yuejian_22.Activity.ClubDetailActivity;
import com.example.admin.yuejian_22.Bean.ClubList;
import com.example.admin.yuejian_22.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Admin on 2017/10/11.
 */

public class ClubSearchAdapter extends RecyclerView.Adapter  {
    private Context Contexts;
    private List<ClubList> clubListsearch;
    private LayoutInflater LayoutInflater;
    public ClubSearchAdapter(Context Contexts, List<ClubList> clubListList) {
        this.Contexts = Contexts;
        this.clubListsearch = clubListList;
        LayoutInflater = LayoutInflater.from(Contexts);
    }
    public void getSearchClub(List<ClubList> clubListsearch)
    {
        this.clubListsearch= clubListsearch ;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_club_search, parent, false);

        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final  ClubList entity=clubListsearch.get(position);
        //final String club_name = entity.getClub_name();
        if (null==entity)return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.club_name_search.setText(entity.getClub_name());
        if (!entity.getThumb().isEmpty()){
            Picasso.with(Contexts).load("http://172.24.10.175/workout/Uploads/"+entity.getThumb()).into(viewHolder.img_club_search);
        }else {
            viewHolder.img_club_search.setImageResource(R.drawable.ic_club);
        }

viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Intent intent =new Intent(Contexts,ClubDetailActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra("Clubid",entity.getId());
        intent.putExtra("userid",entity.getUserid());
        intent.putExtra("clubname",entity.getClub_name());
        intent.putExtra("intro",entity.getIntroduction());
        intent.putExtra("address",entity.getProvince_name() + "-" + entity.getCity_name() + "-" + entity.getDistrict_name());
        intent.putExtra("phone",entity.getClub_tel());
        intent.putExtra("time",entity.getOpen_time());
        intent.putExtra("thumb",entity.getThumb());
       Contexts.startActivity(intent);

    }
});

    }



    public class ViewHolder extends RecyclerView.ViewHolder {

        ImageView img_club_search;
        TextView club_name_search;

        public ViewHolder(View itemView) {
            super(itemView);
            img_club_search = (ImageView) itemView.findViewById(R.id.img_club_search);
            club_name_search = (TextView) itemView.findViewById(R.id.club_name_search);

        }
    }

    @Override
   public int getItemCount() {
        return clubListsearch.size();
  }
}


